//package com.dw.service.impl;
//
//import com.dw.model.message.TestMessage;
//import com.dw.service.MessageQueueService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.rocketmq.client.exception.MQClientException;
//import org.apache.rocketmq.client.producer.DefaultMQProducer;
//import org.apache.rocketmq.client.producer.SendCallback;
//import org.apache.rocketmq.client.producer.SendResult;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.stream.function.StreamBridge;
//import org.springframework.messaging.Message;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.stereotype.Service;
//import org.springframework.util.concurrent.ListenableFutureCallback;
//
//import java.util.UUID;
//import java.util.concurrent.CompletableFuture;
//import java.util.function.BiConsumer;
//
//@Slf4j
//@Service
//public class MessageQueueServiceImpl implements MessageQueueService {
//
//    public static final String BINDING_NAME = "user-output";
////
////    public static final String PRODUCT_CHANNEL = "product-output";
//
//    @Autowired
//    StreamBridge streamBridge;
//    @Override
//    public boolean sendMessageBySync() {
//        TestMessage msg = TestMessage.builder().msgId(UUID.randomUUID().toString()).msgContent("消息内容xxx").build();
//        Message<TestMessage> message= MessageBuilder.withPayload(msg)
//                .setHeader("TAGS", "Sync")          // 备选键名
//                .build();
//        boolean flag = streamBridge.send(BINDING_NAME,message);
//        if(flag){
//            log.info("同步发送成功：{}",message);
//        }else{
//            log.info("同步发送失败：{}",message);
//        }
//        return flag;
//    }
//    @Override
//    public void sendMessageByAsync() {
//        TestMessage msg = TestMessage.builder().msgId(UUID.randomUUID().toString()).msgContent("消息内容xxx").build();
//        Message<TestMessage> message= MessageBuilder.withPayload(msg)
//                .setHeader("TAGS", "Async")
//                .build();
//        boolean flag = streamBridge.send(BINDING_NAME,message);
//        if(flag){
//            log.info("异步发送成功：{}",message);
//        }else{
//            log.info("异步发送失败：{}",message);
//        }
//    }
//
//    @Override
//    public void sendMessageDelay() {
//        TestMessage msg = TestMessage.builder().msgId(UUID.randomUUID().toString()).msgContent("消息内容xxx").build();
//        Message<TestMessage> message= MessageBuilder.withPayload(msg)
//                .setHeader("DELAY", 2)
//                .setHeader("TAGS", "Delay")
//                .build();
//        boolean flag = streamBridge.send(BINDING_NAME,message);
//        if(flag){
//            log.info("异步发送成功：{}",message);
//        }else{
//            log.info("异步发送失败：{}",message);
//        }
//    }
//}
